package com.wavecoler.professor.servlets;

import java.io.IOException;
import javax.servlet.RequestDispatcher;
import javax.servlet.ServletException;
import javax.servlet.http.*;
import com.wavecoler.professor.objects.Word;
import com.wavecoler.professor.dao.WordDAO;

@SuppressWarnings("serial")
public class RegisterWordServlet extends HttpServlet {

	@Override
	protected void doPost(HttpServletRequest request,
			HttpServletResponse response) throws ServletException, IOException {

		String mainWord= request.getParameter("mainword");
		String pluralForm = request.getParameter("pluralform");
		String synonym = request.getParameter("synonym");
		String abbreviation = request.getParameter("abbreviation");

		Word w = new Word();
		w.setMainWord(mainWord);
		w.setPluralForm(pluralForm);
		w.setSynonym(synonym);
		w.setAbbreviation(abbreviation);
		WordDAO.insertWord(w);

		String address = "jsps/ShowWords.jsp";
		RequestDispatcher dispatcher = request.getRequestDispatcher(address);
		dispatcher.forward(request, response);

	}

	protected void doGet(HttpServletRequest request,
			HttpServletResponse response) throws ServletException, IOException {
		doPost(request, response);
	}
}
